<?php
/**
 * Created by PhpStorm.
 * User: C。
 * Date: 2019/8/13
 * Time: 9:04
 */
namespace app\home\controller;

use app\common\model\NewsLike as NewsLikeModel;

/**
 * 资讯点赞收藏
 * Class Newslike
 * @package app\home\controller
 */
class Newslike extends Base
{
    /**
     * [postAdd  添加]
     * @param
     * @return json
     * @author [C。]
     */
    public function add()
    {
        $model = new NewsLikeModel();
        $param = input('param.');
        $user = $this->user;
        try{
            $ilike = $model->findOne(['mid'=>$user['id'],'nid'=>$param['nid']],'id,status');
            if(!empty($ilike)){
                if($ilike['status'] == 1){
                    $model->editData(['status'=>2,'id'=>$ilike['id']]);
                    $name = '取消';
                }elseif($ilike['status'] == 2){
                    $model->editData(['status'=>1,'id'=>$ilike['id']]);
                    $name = '点赞';
                    add_quality($user['id'],29,$user['quality'],4);
                }
            }else{
                $param['mid'] = $user['id'];
                $model->addData($param);
                $name = '点赞';
                add_quality($user['id'],29,$user['quality'],4);
            }
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '失败'.$e->getMessage());
        }
        return admin_json(1, $name.'成功');
    }
}